package com.macro.mall.demo.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.demo.dto.DocSaveDto;
import com.macro.mall.demo.dto.DocSearchRequest;
import com.macro.mall.demo.service.EsDocService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：尚志豪
 * @Package：com.macro.mall.demo.controller
 * @Project：mall-swarm-B
 * @name：EsDocController
 * @Date：2024/10/25 20:37
 */


@RestController
@RequestMapping("/doc")
@Tag(name = "es文档操作")
public class EsDocController {

    @Autowired
    private EsDocService esDocService;


    /**
     * 插入
     */
    @PostMapping("/save")
    @Operation(summary = "批量插入文档")
    public CommonResult save(@RequestBody DocSaveDto docSaveDto){
        esDocService.save(docSaveDto);
        return CommonResult.success("插入成功");
    }


    @DeleteMapping("/delete/{indexName}")
    @Operation(summary = "批量删除文档")
    public CommonResult delete(@PathVariable String indexName){
        esDocService.delete(indexName);
        return CommonResult.success("删除成功");
    }


    @PostMapping("/search")
    public CommonResult source(@RequestBody DocSearchRequest docSearchRequest){
        List list= esDocService.source(docSearchRequest);
        return CommonResult.success(list);
    }
}

